import React, { Component } from "react";
import { createPortal } from "react-dom";

const withPortal = (Comp) => {
  return class extends Component {
    render() {
      return createPortal(<Comp />, document.querySelector("body"));
    }
  };
};

// @withPortal
// class App extends Component {
//   render() {
//     return (
//       <>
//         <h3>装饰器</h3>
//       </>
//     );
//   }
// }

// export default withPortal(App);
// export default App;

// 装饰器只能给类组件使用
// @withPortal
const App = withPortal(() => {
  return <h3>装饰器</h3>;
});

export default App;
